<template>
	<view style="padding: 20px 10px 0px;">
		<view style="display: flex;">
			<image src="../../static/register.png" mode="widthFix"
				style="width: 55px;margin-left: 4vw;height: 5px;margin-right: 3vw;"></image>
			<view style="display: flex;flex-wrap: wrap;align-items: center;">
				<view style="width: 100%;">
					房东直租 省心租
				</view>
				<view class="">
					就找邻里帮租
				</view>
			</view>
		</view>
		<!-- <view style="display: flex;justify-content: center;">
			<image src="../../static/index/denglu.png" mode="widthFix" style="width: 90vw;"></image>
		</view> -->
		<view style="display: flex;margin-left: 4vw;margin-top: 5px;">
			<u-checkbox-group v-model="checkboxValue1" placement="column" @change="checkboxChange">
				<u-checkbox :customStyle="{marginBottom: '8px'}" v-for="(item, index) in checkboxList1" :key="index"
					:label="item.name" :name="item.name">
				</u-checkbox>
			</u-checkbox-group>
			<view style="display: flex;align-items: center;font-size: 13px;color: #FBDE5A;" @click="viewPolicy">
				《邻里帮租用户服务协议》
			</view>
		</view>
		<button style="background-color: #F9D939;border-radius: 60px;font-size: 15px;margin-top: 15px;"
			@click="register">一键登录</button>
		<button style="background-color: #FFFFFF;margin-top: 5px;font-size: 15px;color:#999999 ;"
			@click="cancellation">暂不登录</button>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		get,
		post
	} from '@/serve/method.js'
	const emit = defineEmits(['cancellationone', 'restartone'])
	const checkboxValue1 = ref([]);
	const checkboxList1 = reactive([{
		name: '我已阅读并同意',
		disabled: false,
	}]);
	const checkboxChange = (old) => {
		// checkboxValue1.value.push(n)
		checkboxValue1.value = old
		console.log()
	};
	const viewPolicy = () => {
		uni.navigateTo({
			url: '/pages/index/agreement'
		})
	}
	const cancellation = () => {
		emit('cancellationone')
	}
	const restart = () => {
		emit('restartone')
	}
	const location = ref()
	const register = () => {
		if (checkboxValue1.value.length == 1) {
			// 以下为修改
			wx.login({
				success(res) {
					if (res.code) {
						let urls = "/api/minLogin"
						get(urls, {
							code: res.code
						}).then((res) => {
							console.log(res, 88888)
							if (res.data.unionId == null) {
								console.log('新')
								location.value = '/pages/index/selection'
							}
							let three = {
								"vuex_token": res.data.jwtToken,
								"vuex_user": res.data
							}
							uni.setStorage({
								key: 'lifeData',
								data: three,
								success: function(resone) {
									console.log(resone, '储存');
									if (res.data.unionId == null) {
										console.log(88)
										let urls = "/api/user/addModlueIdAndUnionId"
										post(urls, {
											"unionId": 0,
											"userId": res.data.userId
										}).then((res) => {
											console.log(res)
											uni.redirectTo({
												url: location.value
											});
										})
									} else {
										restart()
									}
								}
							});
						})
					} else {
						console.log('登录失败！' + res.errMsg)
					}
				}
			})
		} else {
			uni.showModal({
				title: '请详细阅读并同意',
				content: '《邻里帮租用户服务协议》',
				showCancel: false,
				success: function(res) {
					if (res.confirm) {
						console.log('用户点击确定');
					}
				}
			});
		}
	}
</script>

<style scoped lang="scss">
	button::after {
		display: none;
		font-size: 14px;
	}
</style>